import { useAppStoreHook } from '@/store/app'

const AccessTokenKey = 'ACCESS_TOKEN'
const RefreshTokenKey = 'REFRESH_TOKEN'

// 获取token
export const getAccessToken = () => {
  // 此处与TokenKey相同，此写法解决初始化时Cookies中不存在TokenKey报错
  return localStorage.getItem(AccessTokenKey)
}

// 刷新token
export const getRefreshToken = () => {
  return localStorage.getItem(RefreshTokenKey)
}

// 设置token
export const setToken = (data: any) => {
  localStorage.setItem(AccessTokenKey, data)
}

// 删除token
export const removeToken = () => {
  localStorage.removeItem(AccessTokenKey)
  localStorage.removeItem(RefreshTokenKey)
}


export const deleteUserCache = () => {
  const appStore = useAppStoreHook()
  localStorage.removeItem('userInfo')
  appStore.clearUserData()
}